<template>
  <div class="pages_content table">
    <el-container>
      <el-header>
        <breaDcrumb />
      </el-header>

      <el-main>
        <!-- 导航 -->
        <div class="tabtop">
          <div v-for="(item, index) in navlist" :key="index" @click="choose(item.id)">
            <div :class="currenindex == index + 1 ? 'active' : 'text'">{{ item.value }}</div>
            <div v-if="currenindex !== index + 1 && currenindex !== index + 2 && index !== 2" class="hr"></div>
          </div>
        </div>
        <!-- 搜索条件 -->
        <div v-loading="pagesLoading">
          <!-- 折叠 -->
          <div class="header_right" @click="showCardNav = !showCardNav">
            <div class="title">搜索</div>
            <div>
              <transition name="from"></transition>
              <span v-show="!showCardNav">
                <i style="margin-right: 5px" class="el-icon-arrow-down"></i>
              </span>
              <transition name="to"></transition>
              <span v-show="showCardNav">
                <i style="margin-right: 5px" class="el-icon-arrow-up"></i>
              </span>
            </div>
          </div>
          <div v-show="showCardNav" class="hr"></div>
          <!-- 搜索内容 -->
          <el-collapse-transition>
            <div v-show="showCardNav" style="padding-top:18px">
              <el-form :inline="true" label-width="110px">
                <!-- 搜索条件1 -->
                <el-form-item v-if="currenindex==1" label-width="160px">
                  <span slot="label">原物料运输供应商</span>
                  <div style="width:240px;height:36px;display:flex;">
                    <div :title="searchText" style="width:180px;padding:0 10px;border-bottom: 1px solid #bbb;margin-right:5px;" class="ellipsis">{{searchText}}</div>
                    <el-button class="bottom_all_two" @click="getsearchData(),search=true">选择</el-button>
                  </div>
                </el-form-item>
                <el-form-item v-if="currenindex==1">
                  <span slot="label">结算时间段</span>
                  <el-date-picker v-model="datePicker" style="height:36px" type="datetimerange" unlink-panels align="right" start-placeholder="开始时间" end-placeholder="结束时间" :default-time="['12:00:00', '08:00:00']" value-format="yyyy-MM-dd HH:mm:ss">
                  </el-date-picker>
                </el-form-item>
                <!-- 搜索条件2 -->
                <el-form-item v-if="currenindex==2">
                  <span slot="label">运输供应商</span>
                  <el-select v-model="tableParam.tranSupplierId" placeholder="请选择">
                    <el-option v-for="(item,index) in unitIdList" :key='index' :label="item.tranSupplier" :value="item.tranSupplierId"></el-option>
                  </el-select>
                </el-form-item>
                <el-form-item v-if="currenindex==2">
                  <span slot="label">运输物料</span>
                  <el-select v-model="tableParam.rawNameId" placeholder="请选择">
                    <el-option v-for="(item,index) in rawList" :key='index' :label="item.rawName" :value="item.rawNameId"></el-option>
                  </el-select>
                </el-form-item>
                <el-form-item v-if="currenindex==2">
                  <span slot="label">结算单号</span>
                  <el-input v-model="tableParam.statementNo" placeholder="请输入" clearable></el-input>
                </el-form-item>
                <el-form-item v-if="currenindex==2">
                  <span slot="label">收货时间段</span>
                  <el-date-picker v-model="datePicker" style="height:36px" type="datetimerange" unlink-panels align="right" start-placeholder="开始日期" end-placeholder="结束日期" :default-time="['12:00:00', '08:00:00']" value-format="yyyy-MM-dd HH:mm:ss">
                  </el-date-picker>
                </el-form-item>
                <!-- 搜索条件3 -->
                <el-form-item v-if="currenindex==3">
                  <span slot="label">结算单号</span>
                  <el-input v-model="tableParam.statementNo" placeholder="请输入" clearable></el-input>
                </el-form-item>
                <el-form-item v-if="currenindex==3">
                  <span slot="label">运输供应商</span>
                  <el-select v-model="tableParam.unitId" placeholder="请选择">
                    <el-option v-for="(item,index) in unitIdList" :key='index' :label="item.unitName" :value="item.unitId"></el-option>
                  </el-select>
                </el-form-item>
                <el-form-item v-if="currenindex==3">
                  <span slot="label">提交时间</span>
                  <el-date-picker v-model="datePicker" style="height:36px" type="datetimerange" unlink-panels align="right" start-placeholder="开始时间" end-placeholder="结束时间" :default-time="['12:00:00', '08:00:00']" value-format="yyyy-MM-dd HH:mm:ss">
                  </el-date-picker>
                </el-form-item>
                <el-form-item>
                  <el-button v-if="currenindex==1" icon="el-icon-search" size="medium" class="bottom_all" @click="(tableParam.page = 1), pagesgettableData()">查 询</el-button>
                  <el-button v-else icon="el-icon-search" size="medium" class="bottom_all" @click="(tableParam.page = 1), gettableData()">查 询</el-button>
                  <el-button v-if="currenindex!=1" size="medium" class="bottom_all_two" style="margin-left: 12px" @click="init()">重 置</el-button>
                </el-form-item>
              </el-form>
            </div>
          </el-collapse-transition>
          <div class="hr"></div>
          <!-- 页面内容区 -->
          <div class="card" :style="currenindex!==1?'padding-top:10px':''">
            <!-- 页面功能按钮区 -->
            <div v-show="currenindex==1" class=" card_nav">
              <div>
                <el-button v-if="ButtonList.findIndex(res=>(res.buttonValue=='SHENGCJSD'))!==-1" size="small" class="bottom_three" :disabled="generate.originalList.length==0" @click="statements()">
                  生成结算单
                </el-button>
              </div>
              <div>
              </div>
            </div>
            <!-- 表格数据 -->
            <div v-loading="tableLoading" class="card_info" :style="style">
              <el-table ref="table" :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width: 100%" :data="tableData" tooltip-effect="dark" @selection-change="tableChange">
                <el-table-column v-if="currenindex==1" align="center" type="selection"></el-table-column>
                <template v-for="(item, index2) in table">
                  <el-table-column v-if="item.status" :key="index2" :label="item.label" align="center" :min-width="item.width" :fixed="item.label =='操作'?'right':false">
                    <template slot-scope="scope">
                      <span v-if="item.label == '结算时间段'">
                        {{scope.row.startTime}}至{{scope.row.endTime}}
                      </span>
                      <div v-else-if="item.label == '结算单号'" class="table_link" @click="show( scope.row)">
                        {{ scope.row[item.prop] }}
                      </div>
                      <span v-else-if="item.label == '序号'">
                        {{scope.$index+1}}
                      </span>
                      <span v-else-if="item.label == '内部审核状态'">
                        {{scope.row.auditStatus==1?'待提交':scope.row.auditStatus==2?'审核中':scope.row.auditStatus==3?'通过':'未通过'}}
                      </span>
                      <span v-else-if="item.label == '操作'">
                        <el-button v-if="scope.row.auditStatus==3" size="mini" class="bottom_all_two" @click="userSubmit(scope.row)">
                          发送
                        </el-button>
                        <el-button v-if="billDetails1.auditStatus==1" size="mini" class="bottom_all_two" @click="$router.push({ name: 'sign_Wise_rentunit1', query: { id: scope.row.statementNo, type: 1 } })">提交审核</el-button>
                      </span>
                      <span v-else-if="item.label == '供应商确认'">
                        {{scope.row.supplierConfirm==1?'待查看':scope.row.supplierConfirm==2?'通过':'未发送'}}
                      </span>
                      <span v-else>{{ scope.row[item.prop] }}</span>
                    </template>
                  </el-table-column>
                </template>
              </el-table>
            </div>
            <!-- 翻页 -->
            <!-- <div class="card_bottom">
              <div class="card_bottom_left">
                <div class="top_page_totle">总共{{ total }}条</div>
                <el-pagination :current-page.sync="tableParam.page" :page-size="tableParam.pageSize" layout="prev, pager, next, jumper" :total="total" @current-change="pagesgettableData()"></el-pagination>
              </div>
              <div>
                <el-button size="mini" icon="el-icon-refresh-right" class="bottom_all_two" @click="pagesgettableData()">刷新</el-button>
              </div>
            </div> -->
          </div>
        </div>
      </el-main>
      <div class="card_bottom">
        <div class="card_bottom_left">
          <div class="top_page_totle">总共{{ total }}条</div>
          <el-pagination :current-page.sync="tableParam.page" :page-size="tableParam.pageSize" layout="prev, pager, next, jumper" :total="total" @current-change="pagesgettableData()"></el-pagination>
        </div>
        <div>
          <el-button size="mini" icon="el-icon-refresh-right" class="bottom_all_two" @click="pagesgettableData()">刷新</el-button>
        </div>
      </div>
    </el-container>
    <!-- 选择供应商合同 -->
    <el-dialog v-dialogDrag :visible.sync="search" width="680px" :close-on-click-modal="false">
      <span slot="title" class="dialog-title">选择原物料运输供应商</span>
      <div class="dialoginfo">
        <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width: 100%" :data="searchData" tooltip-effect="dark" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="55">
          </el-table-column>
          <el-table-column align="center" label="原物料运输合同编号" prop="contractNumber"></el-table-column>
          <el-table-column align="center" label="运输物料名称" prop="cargo"></el-table-column>
          <el-table-column align="center" label="供应商单位" prop="supplierName"></el-table-column>
        </el-table>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="search=false">取 消</el-button>
        <el-button class="bottom_all" style="margin-left: 24px" @click="submitsearch">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 原物料结算单 -->
    <el-dialog v-dialogDrag :visible.sync="billDeta" width="1180px" :close-on-click-modal="false">
      <span slot="title" class="dialog-title">原物料运输结算单</span>
      <div ref="html" style="padding:10px 20px">
        <div class="bill_top">
          <span><span class="text">运输供应商：</span>{{billDetails.unitName}}</span>
          <span><span class="text">结算时间段：</span>{{billDetails.startTime}}至{{billDetails.endTime}}</span>
          <span><span class="text">结算单编号：</span>{{billDetails.statementNo}}</span>
        </div>
        <div style="padding:10px 0">
          <span v-if="UserInfo.adminStatus == 1" style="color: #ff0000">公司</span>
          <el-select v-if="UserInfo.adminStatus == 1" ref="selection1" v-model="companyId" style="padding-left:15px;padding-right:40px" @change="setstationIdlist(),$nextTick(()=>{company = $refs.selection1.selectedLabel})">
            <el-option v-for="item in companylist" :key="item.id" :label="item.name" :value="item.id"></el-option>
          </el-select>
          <span style="color: #ff0000">站点名称</span>
          <el-select ref="selection2" v-model="stationId" style="padding-left:15px" @change="get_simple_organizationFun(stationId),$nextTick(()=>{stationName = $refs.selection2.selectedLabel})">
            <el-option v-for="item in stationIdlist" :key="item.id" :label="item.name" :value="item.id"></el-option>
          </el-select>
        </div>
        <div class="bill_title1">结算信息</div>
        <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width: 100%" :data="billList" tooltip-effect="dark">
          <el-table-column label="站点" align="center" prop="receiveStation"></el-table-column>
          <el-table-column label="物料名称" align="center" prop="rawName"></el-table-column>
          <el-table-column label="收货量（吨）" align="center" prop="receiveNum"></el-table-column>
          <el-table-column label="基础单价(元/吨)" align="center" prop="price"></el-table-column>
          <el-table-column label="结算单价(元/吨)" align="center">
            <template slot-scope="scope">
              <el-input v-model="scope.row.settlementPrice" type="Number" style="width:100%" placeholder="请输入" clearable></el-input>
            </template>
          </el-table-column>
          <el-table-column label="结算金额（元）" align="center" prop="">
            <template slot-scope="scope">
              {{scope.row.settlementAmount=Number(scope.row.settlementPrice) *Number(scope.row.receiveNum )}}
            </template>
          </el-table-column>
        </el-table>
        <div class="bill_title">结算合计</div>
        <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width: 100%" :data="totalList" tooltip-effect="dark">
          <el-table-column label="站点" align="center" prop="receiveStation"></el-table-column>
          <el-table-column label="收获量(吨)" align="center" prop="receiveNum"></el-table-column>
          <el-table-column label="结算金额 (元)" align="center" prop="settlementAmount"></el-table-column>
        </el-table>
        <div class="combined">小计：收获量【{{combined(totalList,'receiveNum')}}】，结算金额【{{combined(totalList,'settlementAmount')}}】</div>
      </div>
      <span slot="footer" class="dialog-footer" style="display:flex;justify-content: space-between;">
        <div>
          <el-button class="bottom_all_two" @click="downloadLink">打印结算单</el-button>
          <el-button class="bottom_all_two" @click="combinedSubmit(2)">提交审核</el-button>
        </div>
        <div>
          <el-button class="bottom_all_two" @click="billDeta=false">关闭</el-button>
          <el-button class="bottom_all" style="margin-left: 24px" @click="combinedSubmit(1)">保 存</el-button>
        </div>

      </span>
    </el-dialog>
    <!-- 查看结算单 -->
    <el-dialog v-dialogDrag :visible.sync="billDeta1" width="1180px" :close-on-click-modal="false">
      <span slot="title" class="dialog-title">原物料运输结算单</span>
      <div ref="html" style="padding:10px 20px">
        <div class="bill_top">
          <span><span class="text">客户名称：</span>{{billDetails1.unitName}}</span>
          <span><span class="text">公司：</span>{{billDetails1.company}}</span>
          <span><span class="text">站点名称：</span>{{billDetails1.stationName}}</span>
          <span><span class="text">结算时间：</span>{{billDetails1.startTime}}至{{billDetails1.endTime}}</span>
          <span><span class="text">结算单编号：</span>{{billDetails1.statementNo}}</span>
        </div>
        <div class="bill_title1">结算信息</div>
        <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width: 100%" :data="billDetails1.list" tooltip-effect="dark">
          <el-table-column label="站点" align="center" prop="receiveStation"></el-table-column>
          <el-table-column label="物料名称" align="center" prop="rawName"></el-table-column>
          <el-table-column label="收货量（吨）" align="center" prop="receiveNum"></el-table-column>
          <el-table-column label="基础单价(元/吨)" align="center" prop="price"></el-table-column>
          <el-table-column label="结算单价(元/吨)" align="center" prop="settlementPrice">
          </el-table-column>
          <el-table-column label="结算金额（元）" align="center" prop="settlementAmount">
          </el-table-column>
        </el-table>
        <div class="bill_title">结算合计</div>
        <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width: 100%" :data="totalList1" tooltip-effect="dark">
          <el-table-column label="站点" align="center" prop="receiveStation"></el-table-column>
          <el-table-column label="收获量(吨)" align="center" prop="receiveNum"></el-table-column>
          <el-table-column label="结算金额 (元)" align="center" prop="settlementAmount"></el-table-column>
        </el-table>
        <div class="combined">小计：收货量【{{combined(totalList1,'receiveNum')}}】，结算金额【{{combined(totalList1,'settlementAmount')}}】</div>
      </div>
      <span slot="footer" class="dialog-footer" style="display:flex;justify-content: space-between;">
        <div>
          <el-button class="bottom_all_two" @click="downloadLink">打印结算单</el-button>
          <el-button v-if="billDetails1.auditStatus==1" class="bottom_all_two" @click="combinedSubmit(3)">提交审核</el-button>
        </div>
        <div>
          <el-button class="bottom_all_two" @click="billDeta1=false">取 消</el-button>
        </div>

      </span>
    </el-dialog>
    <!--选择发送的人员-->
    <!-- <el-dialog v-dialogDrag :visible.sync="userDeta" width="620px" :close-on-click-modal="false">
      <span slot="title" class="dialog-title">请选择接收账号</span>
      <div style="padding:0 10px">
        <el-checkbox-group v-model="userarr">
          <template v-for="(item,index) in useroptons">
            <el-checkbox :key="index" style="line-height:26px" :label="item.id">{{item.name}}</el-checkbox>
          </template>
        </el-checkbox-group>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="userDeta=false">取 消</el-button>
        <el-button class="bottom_all" :disabled="userarr.length==0" style="margin-left: 24px" @click="userSubmit()">发 送</el-button>
      </span>
    </el-dialog> -->
  </div>
</template>

<script>
import mixin from "@/mixins/ICPSmixin.js";
import {
  get_contract_list,
  queryPage1,
  generate_statement,
  save_or_update_detail,
  get_supplier_list,
  queryPage3,
  queryPage2,
  get_search_conditions,
  get_statement_detail,
  update_status,
  Download
} from "@/api/wise/Wise_rentunit/Wise_rentunit1.js";
import { _debounce } from '@/utils/utils.js'
import { getUserInfo } from "@/utils/auth.js";
import { getcompany, getUserAutList, get_simple_organization } from "@/api/common.js";
import { get_station_list } from "@/api/smart/stocksake.js";
import html2canvas from 'html2canvas';
import {
  // queryUserByID,
  informClient
} from "@/api/wise/Wise_contactsbusiness/Wise_contactsbusiness.js";
export default {
  mixins: [mixin],
  data() {
    return {
      UserInfo: '',
      companyId: '',
      company: '',
      companylist: [],
      stationId: '',
      stationName: '',
      stationIdlist: [],
      pagesLoading: false,
      /*表格增删改查及下载接口*/
      queryPage: '',
      download: Download,
      /*表格数据*/
      table: [],
      table1: [
        { label: "运输供应商", width: "auto", prop: "tranSupplier", status: true },
        { label: "运输物料", width: "120", prop: "rawName", status: true },
        { label: "运输车辆", width: "auto", prop: "carNo", status: true },
        { label: "原物料供应商", width: "120", prop: "rawSupplierName", status: true },
        { label: "起运地点", width: "auto", prop: "startAddress", status: true },
        { label: "收货站点", width: "120", prop: "receiveStation", status: true },
        { label: "收货量（吨）", width: "auto", prop: "receiveNum", status: true },
        { label: "收货时间", width: "120", prop: "actualReceiveTime", status: true },
        { label: "单价（元/吨）", width: "120", prop: "price", status: true },
        { label: "结算金额（元）", width: "120", prop: "settlementAmount", status: true },
      ],
      table2: [
        { label: "运输供应商", width: "auto", prop: "tranSupplier", status: true },
        { label: "运输物料", width: "120", prop: "rawName", status: true },
        { label: "运输车辆", width: "auto", prop: "carNo", status: true },
        { label: "原物料供应商", width: "120", prop: "rawSupplierName", status: true },
        { label: "起运地点", width: "auto", prop: "startAddress", status: true },
        { label: "收货站点", width: "120", prop: "receiveStation", status: true },
        { label: "收货量（吨）", width: "auto", prop: "receiveNum", status: true },
        { label: "收货时间", width: "120", prop: "actualReceiveTime", status: true },
        { label: "单价（元/吨）", width: "120", prop: "price", status: true },
        { label: "结算金额（元）", width: "120", prop: "settlementAmount", status: true },
        { label: "结算单号", width: "120", prop: "statementNo", status: true },
      ],
      table3: [
        { label: "序号", width: "50", prop: "", status: true },
        { label: "结算单号", width: "300", prop: "statementNo", status: true },
        { label: "运输供应商", width: "140", prop: "unitName", status: true },
        { label: "结算时间段", width: "310", prop: "", status: true },
        { label: "结算总金额（元）", width: "140", prop: "statementAmount", status: true },
        { label: "提交时间", width: "160", prop: "submitTime", status: true },
        { label: "内部审核状态", width: "120", prop: "", status: true },
        { label: "操作", width: "140", prop: "", status: true },
        { label: "供应商确认", width: "120", prop: "", status: true },
      ],
      pagesType: 0,
      /**导航栏*/
      navlist: [
        {
          value: "待结算",
          id: 1,
        },
        {
          value: "已结算",
          id: 2,
        },
        {
          value: "结算单",
          id: 3,
        },
      ],
      currenindex: 1,
      /**时间*/
      datePicker: [],
      /**搜索条件1*/
      searchText: '',
      search: false,
      searchData: [],
      searchradio: [],
      /**生成结算的数据*/
      generate: {
        originalList: [],
        contractIdList: [],
        startTime: '',
        endTime: '',
        statementNo: ''
      },
      /*结算单详情*/
      billDeta: false,
      billDetails: {},
      billList: [],
      totalList: [],
      unitIdList: [],
      rawList: [],
      billDeta1: false,
      billDetails1: {
        list: []
      },
      totalList1: [
      ],
      userDeta: false,
      useroptons: [],
      userarr: [],
      low: {},
    };
  },
  async created() {
    /*存储拷贝的原初始化fromDate数据*/
    this.UserInfo = getUserInfo();
    if (this.UserInfo.adminStatus == 1) {
      /**通过typeId为公司类型id查询所有公司 */
      getcompany({ typeId: "19da56b9e85648059e3cf1e7da497da4" }).then((res) => {
        this.companylist = res.data;
      });
    } else {
      this.stationIdlist = await getUserAutList(true)
    }
  },
  watch: {
    /**导航切换*/
    currenindex: {
      handler() {
        this.tableData = []
        this.datePicker = []
        this.tableParam = this.$options.data().tableParam
        if (this.currenindex == 1) {
          this.searchText = ''
          this.table = this.table1;
          this.tableParam.contractIdList = []
          this.queryPage = queryPage1
        }
        if (this.currenindex == 2) {
          this.getsearchData()
          this.table = this.table2;
          this.queryPage = queryPage2
          this.gettableData()
        }
        if (this.currenindex == 3) {
          this.getsearchData()
          this.table = this.table3;
          this.queryPage = queryPage3
          this.tableParam.statementType = 1
          this.gettableData()
        }
        this.pagesLoading = false
        //此处为执行的函数或者方法
      },
      deep: false,
      immediate: true,
    },
    /**时间选择*/
    datePicker() {
      if (this.datePicker) {
        this.tableParam.startTime = this.datePicker[0]
        this.tableParam.endTime = this.datePicker[1]
      } else {
        this.tableParam.startTime = ''
        this.tableParam.endTime = ''
      }
    },
    /**table1默认全选*/
    tableData() {
      if (this.tableData.length !== 0 && this.currenindex == 1) {
        this.$refs.table.toggleAllSelection()
        this.generate.startTime = this.tableParam.startTime
        this.generate.endTime = this.tableParam.endTime
        this.generate.contractIdList = this.tableParam.contractIdList
        this.generate.unitId = this.searchradio[0].supplierId
        this.generate.unitName = this.searchradio[0].supplierName
        this.generate.contractId = this.searchradio.map(res => (res.id)).join(',')
      }
    },
    /**结算合计*/
    billList: {
      handler() {
        this.settotalList()
      },
      deep: true,
      immediate: false,
    },
  },
  methods: {
    downloadLink() {
      this.$Download(this.download, { statementNo: this.low.statementNo, dataType: 1 })
    },
    /**通过站点查询公司 */
    get_simple_organizationFun(id) {
      get_simple_organization({ id: id }).then((res) => {
        this.companyId = res.data.id
        this.company = res.data.name
      });//查询站点所属公司
    },
    /*根据公司获取站点*/
    setstationIdlist() {
      get_station_list({ parentId: this.fromDate.companyId }).then((res) => {
        this.stationIdlist = res.data;
      });
    },
    init() {
      this.tableData = []
      this.datePicker = []
      this.tableParam = this.$options.data().tableParam
      if (this.currenindex == 3) {
        this.tableParam.statementType = 1
      }
      this.gettableData()
    },
    /**结算合计*/
    settotalList: _debounce(function () {
      let _this = this
      _this.totalList = []
      this.billList.forEach(res => {
        let index = _this.totalList.findIndex(item => (item.receiveStation == res.receiveStation))
        if (index == -1) {
          _this.totalList.push({ receiveStation: res.receiveStation, receiveNum: res.receiveNum, settlementAmount: res.settlementAmount })
        } else {
          _this.totalList[index].receiveNum = Number(res.receiveNum) + Number(_this.totalList[index].receiveNum)
          _this.totalList[index].settlementAmount = Number(res.settlementAmount) + Number(_this.totalList[index].settlementAmount)
        }
      })
    }, 500),
    /**合计*/
    combined(arr, item) {
      let num = 0
      arr.forEach(res => {
        num = Number(res[item]) + num
      })
      return num.toFixed(2)
    },
    /**导航栏切换*/
    choose(pages) {
      this.pagesLoading = true
      this.currenindex = pages;
    },
    /**获取对应的搜搜添加*/
    getsearchData() {
      let _this = this
      if (_this.currenindex == 1) {
        get_contract_list().then(res => {
          _this.searchData = res.data
        })
      }
      if (_this.currenindex == 2) {
        get_search_conditions().then(res => {
          _this.unitIdList = res.data.supplier
          _this.rawList = res.data.raw
        })
        console.log()
      }
      if (_this.currenindex == 3) {
        get_supplier_list({ statementType: 1 }).then(res => {
          _this.unitIdList = res.data
        })
      }
    },
    /**合同列表选中*/
    handleSelectionChange(val) {
      this.searchradio = val
    },
    /**确定选择运输合同*/
    submitsearch() {
      let id = this.searchradio[0].supplierId
      for (let a = 0; a < this.searchradio.length; a++) {
        if (this.searchradio[a].supplierId !== id) {
          console.log(this.searchradio[a].id)
          this.$message({
            message: '警告哦，请先同一供应商进行结算！！！',
            type: 'warning'
          });
          return
        }
      }
      this.tableParam.contractIdList = this.searchradio.map(res => {
        return res.id
      })
      this.searchText = this.searchradio.map(res => {
        return res.supplierName + '-' + res.id
      }).join(',')
      this.search = false
    },
    /**查询 */
    pagesgettableData() {
      if (this.tableParam.contractIdList && this.tableParam.contractIdList.length !== 0 && this.datePicker && this.datePicker.length !== 0) {
        this.gettableData()
        return
      }
      this.$message({
        message: '警告哦，请先选择供应商和时间段后查询',
        type: 'warning'
      });
    },
    /**表格选中数据*/
    tableChange(val) {
      this.generate.originalList = val
    },
    /**生成结算单*/
    statements() {
      generate_statement(this.generate).then(res => {
        this.billDetails = res.data
        this.billList = JSON.parse(JSON.stringify(res.data.list))
        this.billDeta = true
      })
    },
    /**提交结算单*/
    async  combinedSubmit(type) {
      let _this = this
      if (type == 3) {
        this.$router.push({ name: "sign_Wise_rentunit1", query: { id: this.low.statementNo, type: 1 } })
        return
      }
      let obj = new Object()
      if (_this.companyId == '' && _this.UserInfo.adminStatus == 1) {
        _this.$message({
          message: '请选择公司',
          type: 'warning'
        });
        return
      }
      if (_this.stationId == '') {
        _this.$message({
          message: '请选择站点',
          type: 'warning'
        });
        return
      }
      await html2canvas(this.$refs.html).then((res) => {
        let url = res.toDataURL('image/png');
        console.log(url)
        obj.picture = url
      })
      obj.company = _this.company
      obj.companyId = _this.companyId
      obj.stationId = _this.stationId
      obj.stationName = _this.stationName
      obj.statementNo = _this.billDetails.statementNo
      obj.unitId = _this.billDetails.unitId
      obj.unitName = _this.billDetails.unitName
      obj.startTime = _this.billDetails.startTime
      obj.endTime = _this.billDetails.endTime
      obj.submitTime = new Date().Format('yyyy-MM-dd hh:mm:ss')
      obj.statementAmount = _this.combined(_this.totalList, 'settlementAmount')
      obj.auditStatus = 3
      obj.operation = 1
      obj.originalList = _this.billDetails.originalList
      obj.contractId = _this.tableParam.contractIdList.join(',')
      obj.list = _this.billList
      save_or_update_detail(obj).then(res => {
        if (res.code == 1001) {
          _this.billDeta = false
          if (type == 2) {
            this.$router.push({ name: "sign_Wise_rentunit1", query: { id: res.data, type: 1 } });
            return
          }
          _this.gettableData()
        }
      })
    },
    show(low) {
      this.low = low
      get_statement_detail({ statementNo: low.statementNo, mark: 1 }).then(res => {
        if (res.code == 1001) {
          this.billDetails1 = res.data
          this.totalList1 = []
          res.data.list.forEach(res => {
            let index = this.totalList1.findIndex(item => (item.receiveStation == res.receiveStation))
            if (index == -1) {
              this.totalList1.push({ receiveStation: res.receiveStation, receiveNum: res.receiveNum, settlementAmount: res.settlementAmount })
            } else {
              this.totalList1[index].receiveNum = Number(res.receiveNum) + Number(this.totalList1[index].receiveNum)
              this.totalList1[index].settlementAmount = Number(res.settlementAmount) + Number(this.totalList1[index].settlementAmount)
            }
          })
          this.billDeta1 = true
        }
      })
    },
    /**结算单发给供应商*/
    // send(low) {
    //   this.low = low
    //   this.userarr = []
    //   this.useroptons = []
    //   queryUserByID({ id: low.contractId }).then(res => {
    //     this.useroptons = JSON.parse(res.data)
    //     this.userDeta = true
    //   })
    // },
    async userSubmit(low) {
      this.$confirm('确认发送?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        cancelButtonClass: 'bottom_all_two',
        confirmButtonClass: 'bottom_all',
        type: 'warning'
      }).then(async () => {
        let json = {
          contractId: low.contractId,
          type: 4,
          settlementId: low.id,
          settlementNo: low.statementNo,
          times: low.startTime + '-' + low.endTime,
          money: low.statementAmount,
          applyForTime: low.submitTime,
          imgUrl: low.picture,
        }
        // let arr = this.userarr.map(res => (new useritem(res)))
        await informClient(json).then(res => {
          if (res.code == 1001) {
            update_status({
              statementNo: low.statementNo,
              supplierConfirm: 1,
              statusType: 2,            }).then(() => { })
            this.$message({
              message: '发送成功',
              type: 'success'
            });
            this.gettableData()
            this.userDeta = false
          }
        })
      })
    },
  },
};
</script>

<style lang="scss" scoped>
.dialoginfo {
  padding: 20px 20px 0 20px;
  max-height: 400px;
  overflow: auto;
}
.tabtop {
  width: 571px;
}
.el-input,
.el-select {
  width: 240px;
}
/*
 <el-link class="table_link" :underline="false">查看配合比</el-link>*/
.table_link {
  margin: 0 10px;
  color: $bg_color;
  cursor: pointer;
}

.table_link:hover {
  opacity: 0.8;
}
.bill_top {
  display: flex;
  justify-content: space-between;
  line-height: 40px;
  flex-wrap: wrap;
  .text {
    font-weight: 600;
    color: #000;
  }
}
.bill_title {
  font-size: 18px;
  font-weight: 600;
  padding: 15px 0;
}
.bill_title1 {
  font-size: 18px;
  font-weight: 600;
  padding: 20px 0;
}
.bill_subtitle {
  padding: 20px 0;
  > span {
    padding-right: 20px;
  }
  .text {
    color: #000;
  }
}
.combined {
  border: 1px solid #ebeef5;
  text-align: center;
  line-height: 40px;
}
</style>
